<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><s:property value="formBean.order.typeS" /> <s:property
		value="formBean.order.statusS" /></title>
<%@ include file="../../../common/Style.jsp"%>
<script src='http://127.0.0.1:8000/CLodopfuncs.js'></script>
<script src='http://127.0.0.1:18000/CLodopfuncs.js'></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/conf_files/js/lodop/headProcureLodop.js?v=10.15"></script>
<script type="text/javascript">

var isPreview = false;

function saveToJinsuan(){
	var info = "你确定要导入单据到精算?";
	
	$.messager.confirm('确认', info, function(r){
		if (r){
			$.messager.progress({
				title : '提示',
				text : '数据处理中，请稍后....'
			});
			var url = "<%=request.getContextPath()%>/action/supplierPurchaseJSON!saveToJinSuan";
			var params=$("#purchaseOrderForm").serialize();  
			$.post(url,params, completeSaveOrderToJinSuanBackProcess,"json");	
		} 
	});
}
function completeSaveOrderToJinSuanBackProcess(data){
	$.messager.progress('close');
    var response = data;
	var returnCode = response.returnCode;
	if (returnCode != SUCCESS)
		$.messager.alert('错误', response.message, 'error');
	else {
		$.messager.alert({
			title: '成功',
			closable: false,
			msg: response.message,
			fn: function(){
				parent.closeTab();
			}
		});
    }	
}
/**
 * to submit the order to account
 */
function cancelOrder(){
	$.messager.confirm('确认', "确认红冲单据", function(r){
		if (r){
			$.messager.progress({
					title : '提示',
					text : '数据处理中，请稍后....'
				});
			var params = $("#purchaseOrderForm").serialize();  
			$.post("<%=request.getContextPath()%>/action/supplierPurchaseJSON!cancelPurchase",params, cancelOrderBKProcess,"json");
		}});
}
function cancelOrderBKProcess(data){
	var response = data;

	var returnCode = response.returnCode;
	var returnMsg = response.message;
	if (returnCode == SUCCESS){		   
		
		$.messager.alert({
			title: '消息',
			msg: "成功红冲单据",
			fn: function(){
				parent.closeTab();
			}
		});
	} else {
		$.messager.progress('close'); 
        $.messager.alert('错误', returnMsg, 'error');
    }
}

function updateOrderComment(){
    var url = "<%=request.getContextPath()%>/action/supplierPurchaseJSON!updateOrderComment";
    var params=$("#purchaseOrderForm").serialize();  
    $.post(url,params, updateOrderCommentBackProcess,"json");	
}
function updateOrderCommentBackProcess(data){
	var returnValue = data.returnCode;
	if (returnValue == SUCCESS)
	    $.messager.alert('消息', data.message, 'info');
	else 
		$.messager.alert('操作失败', data.message, 'error');
}
function copyOrderToWholeSales(priceMode){
    var url = "<%=request.getContextPath()%>/action/supplierPurchaseJSON!copyPurchaseOrder2WholeSales";
    var params=$("#purchaseOrderForm").serialize();  
    params = params + "&formBean.indicator=" + priceMode;

    $.post(url,params, copyPurchaseOrder2WholeSalesBackProcess,"json");	
}
function copyPurchaseOrder2WholeSalesBackProcess(data){
    var response = data;
	var returnCode = response.returnCode;

	if (returnCode != SUCCESS)
	    $.messager.alert('导出单据失败', response.message, 'error');
	else {
        $.messager.alert('导出单据成功', "导出单据成功,单据号 " + response.returnValue, 'info');
    }	
}

function downloadOrder(){
	var url = "<%=request.getContextPath()%>/action/supplierPurchaseJSP!downloadPurchase";
	 document.purchaseOrderForm.action = url;
	 document.purchaseOrderForm.submit();
}

function exportOrder(){
	var url = "<%=request.getContextPath()%>/action/supplierPurchaseJSP!exportOrder";
	 document.purchaseOrderForm.action = url;
	 document.purchaseOrderForm.submit();
}
$(document).ready(function(){
	parent.$.messager.progress('close'); 
});



/**
 * 查看图片详情
 */
function viewImgP(barcode){
	
	viewImg(barcode);
}

</script>

</head>
<body>

	<s:form action="/action/inventoryOrder!previewOrder" method="POST"
		name="purchaseOrderForm" id="purchaseOrderForm" theme="simple"
		enctype="multipart/form-data">
		<s:hidden name="formBean.order.id" id="orderId" />

		<table cellpadding="0" cellspacing="0" style="width: 90%"
			align="center" class="OuterTable">
			<tr class="title">
				<td colspan="7"><s:if test="formBean.order.type == 1">
						<font style="color: red"><s:property
								value="formBean.order.typeS" /> </font>
					</s:if>
					<s:else>
						<s:property value="formBean.order.typeS" />
					</s:else> <s:property value="formBean.order.statusS" /></td>
			</tr>

			<tr height="10">
				<td colspan="7"><hr /></td>
			</tr>

			<tr>
				<td colspan="7">
					<table cellpadding="0" cellspacing="0" style="width: 100%"
						border="0" id="org_table">
						<tr class="PBAOuterTableTitale" align="left">
							<th>&nbsp;</th>
							<th>供应商名字&nbsp;:&nbsp;<s:property
									value="formBean.order.supplier.name" />&nbsp&nbsp&nbsp&nbsp&nbsp货品点数&nbsp;
								:&nbsp;<s:property value="formBean.order.orderCounter.name" />
							</th>
							<th>订单号&nbsp;:&nbsp;<s:property value="formBean.order.id" />
							</th>
						</tr>
						<tr class="PBAOuterTableTitale" align="left">
							<th>&nbsp;</th>
							<th>上欠&nbsp;:&nbsp;<s:property
									value="formBean.order.preAcctAmt" />&nbsp&nbsp&nbsp&nbsp&nbsp下欠&nbsp;
								:&nbsp;<s:property value="formBean.order.postAcctAmt" />
							</th>
							<th>库房&nbsp;:&nbsp;<s:property value="formBean.order.store.name"/> </th>
						</tr>
						<tr height="10">
							<th colspan="3"></th>
						</tr>
						<tr height="10">
							<td colspan="3">
								<table class="easyui-datagrid" style="height: 400px"
									data-options="singleSelect:true,border : false">
									<thead>
										<tr align="center" class="PBAOuterTableTitale" height="22">
											<th data-options="field:'1',width:40">&nbsp;</th>
											<th data-options="field:'2',width:90">条型码</th>
											<th data-options="field:'3',width:60">年份</th>
											<th data-options="field:'4',width:50">季度</th>
											<th data-options="field:'5',width:90">产品品牌</th>
											<th data-options="field:'6',width:100">产品货号</th>
											<th data-options="field:'8',width:60">颜色</th>
											<th data-options="field:'18',width:100">公司货号</th>
											<th data-options="field:'20',width:100">厂家货号</th>
											<th data-options="field:'7',width:110">货品类别</th>											
											<th data-options="field:'9',width:60">单位</th>
											<th data-options="field:'10',width:50">数量</th>
											<th data-options="field:'17',width:90">默认进价</th>
											<th data-options="field:'19',width:90">折扣</th>
											<th data-options="field:'11',width:90">进价 (单价)</th>
											<th data-options="field:'15',width:90">进价 (总价)</th>
											<th data-options="field:'12',width:90">批发价(单价)</th>
											<th data-options="field:'16',width:90">批发价(总价)</th>
											<th data-options="field:'13',width:60" align="center">图片</th>
											<th data-options="field:'14',width:10"></th>
										</tr>
									</thead>
									<tbody id="inventoryTable">
										<s:iterator value="formBean.order.productList" status="st"
											id="orderProduct">
											<tr id="row<s:property value="#st.index"/>"
												class="excelTable" align="center">
												<td align="center"><s:property value="#st.index +1" /></td>
												<td><s:property value="#orderProduct.pb.barcode" />
													<input type="hidden"  id="barcode<s:property value="#st.index"/>" readonly="readonly" value="<s:property value="#orderProduct.pb.barcode"/>"/></td>
												<td><s:property
														value="#orderProduct.pb.product.year.year" /></td>
												<td><s:property
														value="#orderProduct.pb.product.quarter.quarter_Name" /></td>
												<td><s:property
														value="#orderProduct.pb.product.brand.brand_Name" /></td>
												<td><s:property
														value="#orderProduct.pb.product.productCode" /> <s:property
														value="#orderProduct.pb.product.numPerHand" /></td>
												<td><s:property value="#orderProduct.pb.color.name" /></td>		
												<td><s:property
														value="#orderProduct.pb.product.productIdentity" /> </td>
												<td><s:property
														value="#orderProduct.pb.product.factoryCode" /> </td>
												<td><s:property value="#orderProduct.pb.product.categoryName" /></td>		
												
												<td><s:property value="#orderProduct.pb.product.unit" /></td>
												<td><s:property value="#orderProduct.quantity" /></td>
												<td><s:property value="#orderProduct.pb.product.recCost" /></td>
												<td><s:text name="format.price">
														<s:param value="#orderProduct.discount" />
													</s:text></td>
												<td><s:text name="format.totalPrice">
														<s:param value="#orderProduct.recCost" />
													</s:text></td>
												<td><s:text name="format.totalPrice">
														<s:param value="#orderProduct.totalRecCost" />
													</s:text></td>													
												<td><s:text name="format.totalPrice">
														<s:param value="#orderProduct.wholeSalePrice" />
													</s:text></td>
												<td><s:text name="format.totalPrice">
														<s:param value="#orderProduct.totalWholeSalePrice" />
													</s:text></td>													
												<td><img src="<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/img3.png" border="0" onclick="viewImgP(<s:property value="#orderProduct.pb.barcode"/>)"   style="cursor:pointer;"/></td>
												<td></td>
											</tr>
										</s:iterator>
									</tbody>
									<tr class="PBAOuterTableTitale" height="22" align="center">
										<td align="center">总计</td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td></td>
										<td><s:property value="formBean.order.totalQuantity" /></td>
										<td></td>
										<td></td>
										<td><s:text name="format.totalPrice">
												<s:param value="formBean.order.totalRecCost" />
											</s:text></td>
										<td></td>
										<td></td>
										<td><s:text name="format.totalPrice">
												<s:param value="formBean.order.totalWholePrice" />
											</s:text></td>
										<td>&nbsp;</td>
										<td>&nbsp;</td>
									</tr>
								</table>



							</td>
						</tr>

						<tr height="10">
							<td colspan="3" align="left"></td>
						</tr>
						<tr height="10" class="InnerTableContent">
							<td align="center">备注</td>
							<td colspan="2"><input name="formBean.order.comment" data-options="prompt:'请输入采购备注信息'"
								id="comment" class="easyui-textbox" style="width: 500px"
								value="<s:property value="formBean.order.comment"/>"><a
								id="btn2" href="#" class="easyui-linkbutton"
								data-options="iconCls:'icon-edit'"
								onclick="updateOrderComment();">修改备注</a></td>
						</tr>
						<tr class="InnerTableContent">
							<td width="5%" height="27" align="center">优惠</td>
							<td width="85%"><s:property
									value="formBean.order.totalDiscount" /></td>
							<td width="10%"></td>

						</tr>
					</table>
				</td>
			</tr>
			<tr height="10">
				<td>&nbsp;</td>
				<td></td>
				<td></td>
				<td colspan="2">
				<a id="btn2" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="saveToJinsuan();">导入精算</a>
				<s:if test="#session.LOGIN_USER.containFunction('supplierPurchaseJSON!cancelPurchase') && formBean.canCancel">
				    <a id="btn2" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-no'" onclick="cancelOrder();">红冲单据</a>
				</s:if>
					&nbsp;&nbsp;
					<a id="btn3" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-print'" onclick="printOrder(false);">打印单据</a>
					<a id="btn3" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-print'" onclick="printOrder(true);">打印预览</a>
					<a id="btn2" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="copyOrder();">复制单据</a> 
					<a href="javascript:void(0)" id="mb1" class="easyui-menubutton" data-options="iconCls:'icon-redo',menu:'#mm',plain:false">导出到批发销售</a>
					<a id="btn5" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-database'" onclick="downloadOrder();">下载单据</a>
					<a id="btn6" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-print'" onclick="exportOrder();">导出条码打印</a>
					<div id="mm" style="width: 150px;">
						<div data-options="iconCls:'icon-redo',name:'price'" onclick="copyOrderToWholeSales(1);">批发价导出</div>
						<div data-options="iconCls:'icon-redo',name:'quantity'" onclick="copyOrderToWholeSales(2);">采购价导出</div>
					</div></td>
				<td></td>
				<td></td>
			</tr>
		</table>

	</s:form>

</body>
</html>